//
//  WmcResolutionVM.swift
//  YPWatermarkCamera
//
//  Created by Json on 2023/7/11.
//

import UIKit
import YPGraphicEngine

class WmcResolutionVM: WmcBaseVM {
    
    typealias AspectRatio = YPGESunglasses.AspectRatio
    
    var items: [WmcResolutionItem] = []
    /// 画幅比例
    let aspectRatio: AspectRatio
    /// 选中的分辨率级别
    var resolutionLevel: WmcResolution.Level = .standard
    /// 当前选中的item
    var selectedItem: WmcResolutionItem?
    
    // MARK: Init
    init(aspectRatio: AspectRatio) {
        self.aspectRatio = aspectRatio
        super.init()
    }
    
    public required init() {
        fatalError("init() has not been implemented")
    }
    
}

extension WmcResolutionVM {
    
    func initDatasource() {
        // 低清
        let lowRe = WmcResolution(level: .low, aspectRatio: aspectRatio)
        let lowItem = WmcResolutionItem(resolution: lowRe)
        items.append(lowItem)
        // 普清
        let commonRe = WmcResolution(level: .common, aspectRatio: aspectRatio)
        let commonItem = WmcResolutionItem(resolution: commonRe)
        items.append(commonItem)
        // 标清
        let standardRe = WmcResolution(level: .standard, aspectRatio: aspectRatio)
        let standardItem = WmcResolutionItem(resolution: standardRe)
        items.append(standardItem)
        // 高清
        let highRe = WmcResolution(level: .high, aspectRatio: aspectRatio)
        let highItem = WmcResolutionItem(resolution: highRe)
        items.append(highItem)
        
        // 默认选中
        let item = items.first { $0.resolution.level == self.resolutionLevel }
        item?.isSelected = true
        self.selectedItem = item
    }
}
